/**
 * 递归
 */
var FS = require('fs');
var PATH = require('path');
var data = ['dongge','name',['zeus',['1','2'],'yun'],'user'];

function display(data){
    if(Array.isArray(data)){
        function print(i){
            if(i>=data.length){
                return
            }
            display(data[i]);
            print(i+1);
        }
        print(0);
    }else{
        console.log(data);
    }
}
function display_prefex(data,prefex){
    if(Array.isArray(data)){
        function print(i){
            if(i>=data.length){
                return
            }
            display_prefex(data[i],prefex+'**');
            print(i+1);
        }
        print(0);
    }else{
        console.log(prefex+data);
    }
}
//display_prefex(data,'');
function listDir(path,callback){
    FS.readdir(path,function(err,files){
        if(err) throw err;
        function file(i){
            if(i>=files.length)
            {
                if(callback){
                    callback();
                }
                return;
            }
            var fileName = PATH.join(path,files[i]);
            FS.stat(fileName,function(err,stat){
                if(err) throw err;
                if(stat.isDirectory()){
                    console.log('+ '+fileName);
                    listDir(fileName,function(){
                            file(i+1);
                        });
                }else{
                    console.log('- '+fileName);
                    file(i+1);
                }

            })
        }
        file(0);
    })
}

listDir('1');



